package com.whl.mybatis.helper;

import com.whl.common.WhlConstants;

public class PageTemplate {

	public <T> PageInfo<T> query(int pagination, int pagesize, PageLoader<T> pageLoader) {
		if (pagination == 0) {
			pagination = WhlConstants.CUR_PAGE;
		}
		if (pagesize == 0) {
			pagesize = WhlConstants.PAGE_SIZE;
		}
		PageHelper.init(pagination, pagesize);
		try {
			PageInfo<T> pageInfo = PageHelper.afterSetProperties(pageLoader.list());
			return pageInfo;
		} catch (Exception e) {
			throw new RuntimeException(e);
		} finally {
			PageHelper.destory();
		}
	}

}
